package com.yingxin.yxerp.module.activiti.biz.manager;

import com.yingxin.yx.framework.commons.enums.BusinessType;
import com.yingxin.yx.framework.commons.exception.BizException;
import com.yingxin.yxerp.module.activiti.api.BizProcessHandler;
import com.yingxin.yxerp.module.activiti.biz.service.process.FinishDateApplyProcessHandler;
import com.yingxin.yxerp.module.activiti.biz.service.process.InvalidateApplyProcessHandler;
import com.yingxin.yxerp.module.activiti.biz.service.process.RevokeFinishDateApplyProcessHandler;
import com.yingxin.yxerp.module.activiti.biz.service.process.UpdateDateApplyProcessHandler;
import com.yingxin.yxerp.module.print.service.process.PrintApplyProcessHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BizProcessHandlerRouter {

    // 打印申请
    @Autowired
    private PrintApplyProcessHandler printApplyProcessHandler;

    //作废申请
    @Autowired
    private InvalidateApplyProcessHandler invalidateApplyProcessHandler;

    // 完结申请
    @Autowired
    private FinishDateApplyProcessHandler finishDateApplyProcessHandler;

    // 撤销完结申请
    @Autowired
    private RevokeFinishDateApplyProcessHandler revokeFinishDateApplyProcessHandler;

    // 修改申請
    @Autowired
    private UpdateDateApplyProcessHandler updateDateApplyProcessHandler;

    /**
     * 获取biz处理器
     *
     * @param processDefinitionKey
     * @return
     */
    public BizProcessHandler getProcessHandler(String processDefinitionKey) {
        BusinessType businessType = BusinessType.getEnum(processDefinitionKey);
        if (businessType == null) {
            throw new BizException("未知流程");
        }
        switch (businessType) {
            case DYSQ:
                return printApplyProcessHandler;
            case ZFSQ:
                return invalidateApplyProcessHandler;
            case WJSQ:
                return finishDateApplyProcessHandler;
            case XGSQ:
                return updateDateApplyProcessHandler;
            case CXWJSQ:
                return revokeFinishDateApplyProcessHandler;
            default:
                throw new BizException("流程未知");
        }
    }

}
